package com.power.project.dao;

import com.power.base.model.Ha_user;
import com.power.project.model.Ww_user;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.Repository;
import org.springframework.data.repository.query.Param;

import javax.transaction.Transactional;
import java.io.Serializable;
import java.util.List;

/**
 * 持久层(hibernate)
 */
public interface Ww_userDao extends JpaRepository<Ww_user, Serializable>, JpaSpecificationExecutor<Ww_user>, Repository<Ww_user, Serializable>, Ww_userDaoCustom<Ww_user, Serializable> {

    /*
     * 根据userid查询用户
     */
    @Query(" from Ww_user s where  s.userid = :userid ")
    Ww_user getByUserId(String userid);

    List<Ww_user> findByTenantidAndUseridIn(String tenantid, List<String> userIdList);

    @Modifying
    @Transactional
    @Query(value = "update ha_user set deleted = 1 where userid = :userId", nativeQuery = true)
    void deleteByUserId(String userId);

    @Modifying
    @Transactional
    @Query(value = "insert into ha_user (userid, password) VALUE (:#{#user.userid},:#{#user.password})", nativeQuery = true)
    void addUser(@Param("user") Ha_user user);

    @Modifying
    @Transactional
    @Query(value = "update ha_user set  password= :password where userid = :userId", nativeQuery = true)
    void updataByUserId(String userId,String password);

    List<Ww_user> findByUseridIn(List<String> userIds);
}
